<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>新增课程</title>
    <link rel="stylesheet" href="static/layui/css/layui.css">
    <style>
        body{background-color: white}
        .layui-form-label{
            width: 100px;
        }
        .layui-input-block {
            margin-left: 130px;
            min-height: 36px
        }
    </style>
    <script src="static/login/js/jquery.min.js"></script>
</head>
<body class="body">
<!--templates/insert/kcxxgl-->
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>新增课程</legend>
</fieldset>

<form class="layui-form layui-from-pane" style="margin-top:20px" method="post">
    <div class="layui-form-item">
        <label class="layui-form-label">课程名：</label>
        <div class="layui-input-block">
            <input type="text" name="kname"  required  lay-verify="required" autocomplete="off" placeholder="请输入课程名" class="layui-input" style="width: 90%">
        </div>
    </div>

    <div class="w3_agileits_main_grid w3l_main_grid">
            <span class="agileits_grid">
                <label  style="margin-left: 75px;margin-right: 20px">授课教师<i>:</i></label>
                <div class="layui-input-inline">
                   <select name="teacher" id="teacher"></select>
                </div>
            </span>
    </div>
    <br>
    <div class="layui-form-item">
        <label class="layui-form-label">总学时：</label>
        <div class="layui-input-block">
            <input type="number" name="zxs"  required  lay-verify="required" autocomplete="off" placeholder="请输入总学时" class="layui-input" style="width: 90%">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">学分：</label>
        <div class="layui-input-block">
            <input type="number" name="xf" required  lay-verify="required" autocomplete="off" placeholder="请输入学分" class="layui-input" style="width: 90%">
        </div>
    </div>

    <div class="w3_agileits_main_grid w3l_main_grid">
            <span class="agileits_grid">
                <label  style="margin-left: 75px;margin-right: 20px">课程类型<i>:</i></label>
                <div class="layui-input-inline">
                   <select name="kclx" id="kclx">
                       <option value="公共基础课">公共基础课</option>
                       <option value="专业基础课">专业基础课</option>
                       <option value="创新创业课">创新创业课</option>
                       <option value="实践课">实践课</option>
                       <option value="专业任选课">专业任选课</option>
                       <option value="公共任选课">公共任选课</option>
                   </select>
                </div>
            </span>
    </div>
    <br>

    <div class="w3_agileits_main_grid w3l_main_grid">
            <span class="agileits_grid">
                <label  style="margin-left: 75px;margin-right: 20px">课程属性<i>:</i></label>
                <div class="layui-input-inline">
                   <select name="kcsx" id="kcsx">
                       <option value="必修">必修</option>
                       <option value="选修">选修</option>
                   </select>
                </div>
            </span>
    </div>
    <br>

    <div class="w3_agileits_main_grid w3l_main_grid">
            <span class="agileits_grid">
                <label  style="margin-left: 75px;margin-right: 20px">课程性质<i>:</i></label>
                <div class="layui-input-inline">
                   <select name="kcxz" id="kcxz">
                       <option value="实践课">实践课</option>
                       <option value="理论课">理论课</option>
                   </select>
                </div>
            </span>
    </div>
    <br>

    <div class="layui-form-item" style="margin-top:40px">
        <div class="layui-input-block">
            <button class="layui-btn  layui-btn-submit " lay-submit="" lay-filter="demo1">添加</button>
        </div>
    </div>
</form>
<script src="static/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','layer','jquery'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,$=layui.jquery
        $.ajax({
            url:"/selectjs",
            type:"post",
            dataType:"json",
            success: function (result) {
                var optionstring = "";
                for (var j = 0; j < result.count; j++) {
                    optionstring += "<option value='" + result.data[j].id + "'>" + result.data[j].tname + "</option>";
                }
                $("#teacher").html(optionstring);
                form.render('select');
            },
            error:function (e) {
                layer.msg('服务器错误',{icon:2});
            }
        });
        //监听提交
        form.on('submit(demo1)', function(data){
            var teacher = $('#teacher').val();
            var kclx = $('#kclx').val();
            var kcsx = $('#kcsx').val();
            var kcxz = $('#kcxz').val();
            $.ajax({

                url:'/Insertkcxxgl',
                type:'POST',
                dataType:'json',
                data:{kname:data.field.kname,
                    zxs:data.field.zxs,
                    xf:data.field.xf,
                    teacher:teacher,
                    kclx:kclx,
                    kcsx:kcsx,
                    kcxz:kcxz
                },
                success:function (msg) {
                    if(msg){
                        layer.closeAll('loading');
                        layer.load(2);
                        layer.msg("添加成功", {icon: 1});
                        setTimeout(function(){
                            window.parent.location.reload();//修改成功后刷新父界面
                        }, 1000);
                        //加载层-风格

                    }else{
                        layer.msg("添加失败", {icon: 2});
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>